/**
 * 
 */
package cx3k.GUI;

import javax.swing.*;
import java.awt.*;

/**
 * @author Chris
 *
 */
public class SemesterPane extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel semester;
	private Box classBox;
	private ClassDisplay[] classes;
	private JLabel credits;
	private int nextAvialableClass;
	private Course courses[];
	
	public SemesterPane(ScheduledSemester semester) {
		this.setBackground(MainWindow.MAINCOLOR);
		GridBagLayout gbl = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		this.setLayout(gbl);
		
		this.courses = (Course[]) semester.getCourses().toArray();
		this.semester = new JLabel(semester.getTerm());
		this.classBox = Box.createVerticalBox();
		this.classes = new ClassDisplay[courses.length];
		this.nextAvialableClass = 0;
	
		for (int i = 0; i<courses.length; i++) {
			classes[i] = new ClassDisplay(courses[i]);
			classBox.add(classes[i]);
		}
		
		this.credits = new JLabel("0");
		
		
		gbc.gridx = 0;
		gbc.gridy = 0; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 5; 
		gbc.fill = GridBagConstraints.VERTICAL; 
		gbc.anchor = GridBagConstraints.CENTER; 
		gbl.setConstraints(this.semester, gbc);
		this.add(this.semester); 
		
		gbc.gridx = 0;
		gbc.gridy = 1; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 75; 
		gbc.fill = GridBagConstraints.HORIZONTAL; 
		gbc.anchor = GridBagConstraints.LINE_START; 
		gbl.setConstraints(this.classBox, gbc);
		this.add(this.classBox);
		
		Box hbox = Box.createHorizontalBox();
		hbox.add(new JLabel("Total Credits:  "));
		hbox.add(this.credits);
		
		gbc.gridx = 0;
		gbc.gridy = 2; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 20; 
		gbc.fill = GridBagConstraints.VERTICAL; 
		gbc.anchor = GridBagConstraints.LAST_LINE_START; 
		gbl.setConstraints(hbox, gbc);
		this.add(hbox);
	}

	public int addClass(String classID) {
		if (nextAvialableClass == 7) {
			return -1;
		}
		else {
			classes[nextAvialableClass].addClass(classID);
			nextAvialableClass++;
			return 0;
		}
	}
	
	public int addClasses(String classIDs[]) {
		if (nextAvialableClass == 7) {
			return -1;
		}
		else {
			for (int i = 0; i<classIDs.length; i++) {
				classes[nextAvialableClass].addClass(classIDs[i]);
			}
			nextAvialableClass++;
			return 0;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
